package com.liziba.trend.controller;

import com.liziba.trend.api.Index;
import com.liziba.trend.config.IpConfiguration;
import com.liziba.trend.entity.Result;
import com.liziba.trend.entity.StatusCode;
import com.liziba.trend.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: trend
 * @description:
 * @author: liziba
 * @date: 2021-02-03 10:52
 */
@RestController
@CrossOrigin
public class IndexController {

    /**
     * 注入获取基金代码service
     */
    @Autowired
    private IndexService indexService;

    /**
     * 注入获取当前端口configuration
     */
    @Autowired
    private IpConfiguration ipConfiguration;

    /**
     * 获取基金代码数据
     * @return
     * @throws Exception
     */
    @GetMapping("/codes")
    public List<Index> get() throws Exception {
        // 输出当前服务端口号
        System.out.println("hello, current instance port is: " + ipConfiguration.getServerPort());
        // 获取基金代码数据
        List<Index> indexList = indexService.getIndexes();
        return indexList;
    }
}
